<template>
  <div class style="height: 100%;padding: 20px;">
    <div :id="uniqueID" style="height: 100%;width: 100%;"></div>
  </div>
</template>
<script>
import echarts from "echarts";
import uuidv1 from "uuid/v1";
import commonmixins from "@/mixins/bigScreen/commonmixins";

export default {
  name: "commontianqi24h",
  mixins: [commonmixins],
  components: {},
  data() {
    return {
      uniqueID: ""
    };
  },
  computed: {},
  watch: {
    "$store.state.daping.commontianqishishi": {
      handler: function(n, o) {
        this.loadData(n);
      }
    }
  },
  created() {
    this.uniqueID = uuidv1();
  },
  mounted() {
    // this.loadData();
  },
  methods: {
    async loadData(res) {

      let scale = this.$root.setting.scale * this.scalecom;

      let hourForecastData = [];
      if (res.code == 200) {
        res.data.map(item => {
          let time_arr = item['date'].split(" ")[1].split(":")
          hourForecastData.push([time_arr[0] + ':' + time_arr[1], Number(item['temperature'])]);
        })
      }

      var hourOption = {
        // backgroundColor: '#0e2147',
        // title: {
        //   text: "未来24小时天气预报(℃)",
        //   textStyle: {
        //     color: "#fff",
        //     fontSize: 36 * scale,
        //     fontWeight: "bold"
        //   }
        // },
        tooltip: {
          show: true,
          trigger: "axis",
          // formatter: "{a} {b}: {c} ℃",
          textStyle: {
            fontWeight: "normal",
            fontSize: 30 * scale
          }
        },
        grid: {
          left: "5%",
          right: "5%",
          bottom: "5%",
          top: "20%",
          containLabel: true
        },
        legend: {
          show: false, //【2019年11月7日】不展示legend
          type: "scroll",
          // data: Line,
          itemWidth: 18,
          itemHeight: 12,
          textStyle: {
            color: "#F5F5F5",
            fontSize: 30 * scale
          }
        },
        xAxis: [
          {
            //x轴
            type: "category", //数据类型为不连续数据
            boundaryGap: false, //坐标轴两边是否留白
            axisLine: {
              show: true,
              onZero: false, //【2019年12月5日】X 轴或者 Y 轴的轴线是否在另一个轴的 0 刻度上，只有在另一个轴为数值轴且包含 0 刻度时有效。
              lineStyle: {
                color: "#F5F5F5"
              }
            },
            axisLabel: {
              inside: false,
              textStyle: {
                color: "#fff",
                fontWeight: "normal",
                fontSize: 30 * scale
                // lineHeight: 22
              }
              // formatter: function (value, index) {
              //     var year = value.substring(0,4);//不包含最后一个字符
              //     var month = value.substring(4,6);
              //     var day = value.substring(6,8);
              //     var hour = value.substring(8,10);
              //     var minute = value.substring(10,12);

              //     return hour+":"+minute;
              // }
            },
            axisTick: { show: false } //刻度点数轴
            // data:xData,
            // data: ['20:00', '22:00', '00:00', '2:00', '4:00', '6:00', '8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00'],
          }
        ],
        yAxis: [
          {
            //y轴的相关设置
            type: "value", //y轴数据类型为连续的数据
            // name:"单位:℃",
            splitLine: {
              //y轴上的y轴线条相关设置
              show: false
            },
            axisLine: {
              //y轴的相关设置
              show: true,
              lineStyle: {
                color: "#F5F5F5" //y轴颜色
              }
            },
            axisLabel: {
              textStyle: {
                color: "#ffffff",
                fontSize: 30 * scale
              }
            },
            axisTick: { show: false } //刻度点数轴
          }
        ],
        series: [
          {
            name: "温度",
            type: "line", //统计图类型为折线图
            smooth: true, //是否平滑曲线显示
            symbolSize: 0, //数据点的大小，[0,0]//b表示宽度和高度
            lineStyle: {
              //线条的相关设置
              normal: {
                color: "#53f3f3" // 线条颜色
              }
            },
            itemStyle: {
              normal: {
                borderWidth: 5,
                color: "#53f3f3"
              }
            },
            areaStyle: {
              //区域填充样式
              normal: {
                //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    { offset: 0, color: "rgba(9,96,152,0.8)" },
                    { offset: 1, color: "rgba(9,96,152,0.06)" } //9,96,152
                  ],
                  false
                ),
                shadowColor: "rgba(9,96,152, 0.9)", //阴影颜色
                shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
              }
            },
            data: hourForecastData
          }
        ]
      };

      var weatherEchartHour = echarts.init(
        document.getElementById(this.uniqueID)
      );
      weatherEchartHour.setOption(hourOption);
      window.addEventListener("resize", () => {
        weatherEchartHour.resize();
      });
    }
  }
};
</script>
<style lang='scss' scoped>
</style>